var menu;
$(function() {
        /**
         * 快捷菜单
         */
        $("#MianWrap").height($("body").height() - 55);
        getMenu(0);
        createMenu();
        $("#index").click(function() {
            window.location.reload();
        });
        
});
/**
 * 获得菜单
 */
function getMenu(supId) {
    $.ajax({
        type: "POST",
        url: "/sys/getMenu.do",
        data: {
            supId: supId,
            roleId: roleId,
            status: '1'
        },
        dataType: "json",
        async: false,
        success: function(res) {
            if (res.length>0) {
                menu = res;
            } else {
                window.location.href = "doLginOut.do";
            }

        },
        error: function(date) {

        }
    });
}

/**
 * 一级菜单
 */
function createMenu() {
    for (var i = 0; i < menu.length; i++) {
        $("#mainMenu").append("<div id='mainMenu_" + menu[i].id + "' class='panel panel-default menu-border'>" +
            "<div class='panel-heading'>" +
            "<h4 class='panel-title' data-toggle='collapse' data-parent='#mainMenu' onClick=getSecond('" + menu[i].id + "') href='#" + menu[i].id +"'> " + menu[i].name + "</h4>" +
            "</div>" +
            "<div id=" + menu[i].id + " class='panel-collapse  panel-body collapse'></div>" +
            "</div>");
    }
    $($("#mainMenu").children("div").get(0)).addClass("pick-on");
}

/**
 * 二级菜单
 * @param supCode
 */
function getSecond(id) {
    $("#mainMenu div").removeClass("pick-on");
    $("#mainMenu_" + id).addClass("pick-on");
    if ($("#" + id).html() == null || $("#" + id).html() == "") {

        getMenu(id);
        for (var i = 0; i < menu.length; i++) {
            $("#" + id).append("<div id='" + menu[i].id + "' class='menu-div' onmousemove=mouseOver('" + menu[i].id + "') onmouseout=mouseOut('" + menu[i].id + "')  onClick=goUrl('" + menu[i].id + "','" + menu[i].url + "')>" + menu[i].name + "</div>");
        }
    }
}
/**
 * 载入main中页面
 */
function goUrl(id, url) {
    $("#mainMenu div").removeClass("click-on");
    $("#" + id).addClass("click-on");
    $("#main").load(url);
}

function mouseOver(id) {
    $("#" + id).addClass("mouseover");
}

function mouseOut(id) {
    $("#" + id).removeClass("mouseover");
}